<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.yaodian100.com/jsp/yaodian100" prefix="yaodian100" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ page import="com.yaodian100.core.common.utils.ServerValue"%>
<%@page import="java.util.List"%>
<%@page import="com.yaodian100.ec.announcement.entity.Announcement"%>
<%@page import="org.apache.commons.lang.xwork.StringUtils"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>
<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath() %>'/>
<head>
<style type="text/css">
h1 span{visibility:visible;}
</style>
</head>
<!-- 月历 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick-zh-CN.js"></script>
<link rel="stylesheet" type="text/css" href="/css/smoothness.datepick.css" />
<script language="javascript">
$().ready( function() {
	var deleteId;
	$('#sstartDateParam').datepick({minDate: new Date(<%=request.getAttribute("sminDate").toString()%>), showOn:'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '${midContextPath}/images/calendar.gif',dateFormat:"yy-mm-dd"}); 
	$('#sendDateParam').datepick({minDate: new Date(<%=request.getAttribute("sminDate").toString()%>),beforeShow:customRange,showOn: 'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '${midContextPath}/images/calendar.gif',dateFormat:"yy-mm-dd"});
	function customRange (){
		var startDt = $('#sstartDateParam').val(); //起始日
		var endDt = new Date(parseInt(startDt.substring(0,4),10),parseInt(startDt.substring(5,7),10)-1,parseInt(startDt.substring(8,10),10)); //結束日
		return {minDate:endDt}; 
	}
	$("#anndialog").dialog({
		bgiframe: true,
		autoOpen:false,
		height: 150,
		width:250,
		modal: true
	});
	
	$(":a[id*=d_]").click(function(){
		deleteId = $(this).attr("id").split("_")[1];
		$("#anndialog").dialog('open');
	});

	$("#delete_commit").click(function(){
		$("#anndialog").dialog('close');
		$.post("<%=ServerValue.getMidContextPath()%>/memberMessage/delete.do",{anndeleteId:deleteId},delcallback,"json");
		function delcallback(result){
			if(result=='success'){
				window.location.replace("${midContextPath}/memberMessage/search.do?sstartDateParam=${sstartDateParam}&sendDateParam=${sendDateParam}&sannNameParam=${sannNameParam}&sannTypeParam=${sannTypeParam}&sisDeleteParam=${sisDeleteParam}&sshowTypeParam=${sshowTypeParam}&pager.currentPage=${pager.currentPage}");
			}else{
				alert(result);
			}
		}
	});

	$(":a[id*=m_]").click(function(){
		var modifyId = $(this).attr("id").split("_")[1];
		window.location.replace("<%=ServerValue.getMidContextPath()%>/memberMessage/edit.do?annId="+modifyId);
	});

	$("#delete_cancel").click(function(){
		$("#anndialog").dialog('close');
	});
});

function popitup(url) {
	var winl = (screen.width-600)/2;
	var wint = (screen.height-500)/2;
	newwindow=window.open(url,'name','top='+wint+',left='+winl+',height=500,width=600');
}
</script>
<%
@SuppressWarnings("unchecked")
List<Announcement> annList = (List)request.getAttribute("annList");
Announcement ann;
%>
<br />
<h1>会员讯息管理
<span class="f-link"><a href="${midContextPath}/memberMessage/add.do">新增会员讯息</a></span>
</h1>
<div class="data-form"><s:form action="search.do" method="post">
	<b>讯息标题关键字：</b>
	<input name="sannNameParam" type="text" id="sannNameParam"
		value="${sannNameParam}" size="20" maxlength="20">
	<b>起迄时间：</b>
	<input name="sstartDateParam" type="text" id="sstartDateParam"
		value="${sstartDateParam}" size="10" maxlength="10">
    ~ <input name="sendDateParam" type="text" id="sendDateParam"
		value="${sendDateParam}" size="10" maxlength="10">
	<br>
	删除状态：<s:select name="sisDeleteParam" value="%{sisDeleteParam}" headerKey="" headerValue="全部"
	list="annIsDeleteMenu.options" listKey="key" listValue="value.name" />
    <s:hidden name="sshowTypeParam" value="" ></s:hidden>
	<input type="button" value="搜寻" onClick="this.form.submit();" />
</s:form></div>
<br />
<table class="tb-1"  width="100%">
	<thead>
		<tr>
			<th>#</th>
			<th>标题</th>
			<th>上档状态</th>
			<th>起迄时间</th>
			<th>是否删除</th>
			<th>显示顺序</th>
			<th>管理</th>
		</tr>
	</thead>
	<tbody>
		<% DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		for(int i = 0 ; i < annList.size() ; i++){ 
			ann = annList.get(i);
		%>
			<tr class="<%=i%2==0?"bg-yl":"" %>">
			<td>
			<a href="${midContextPath}/memberMessage/view.do?annId=<%=ann.getId()%>" target="_blank" ><%=ann.getId()%></a>
			</td>
			<td><%=ann.getSubject() %></td>
			<td>
			<% long now = new Date().getTime();
			if(ann.getStartDate().getTime()>now){%>
				未上档
			<%}else if(ann.getEndDate().getTime()<now){%>
				已下档
			<%}else{
				if(ann.getIsDelete().equals("Y")){ out.write("<del>");}%>
				上档中
			<%	if(ann.getIsDelete().equals("Y")){ out.write("</del>");}
			}%>
			</td>
			<td>
              <%=dateFormat.format(ann.getStartDate())%>
              ~
              <%= ann.getSpecifyEndDate()!=null && !ann.getSpecifyEndDate().booleanValue()? "永久": dateFormat.format(ann.getEndDate())%>
            </td>
			<td><%=ann.getIsDelete() %></td>
			<td><%=ann.getShowSeq() %></td>
			<td>
			<%if(ann.getIsDelete().equals("N")){ %>
				<a id="m_<%=ann.getId()%>" href="javascript:;" >修改</a>&nbsp;&nbsp;<a id="d_<%=ann.getId()%>" href="javascript:;">删除</a>
			<%} %>
			</td>
			</tr>
		<%} %>
	</tbody>
</table>
<yaodian100:pageutil link="${midContextPath}/memberMessage/search.do" pagerObj="${pager}" />
<div id="anndialog" class="od-cancel-dailog">
<br /><p style="text-align:center;">确定要删除？</p><br />
<div style="text-align:center;"><input type="button" id="delete_commit" value="确&nbsp;定"/>&nbsp;&nbsp;<input type="button" id="delete_cancel" value="取&nbsp;消"/></div></div>